﻿using System.Linq;

namespace DataModel.Managers.SubManage
{
    public class PeriodicityHelper
    {
        /// <summary>
        /// Get bool mask from int number
        /// </summary>
        /// <param name="periodicity"></param>
        /// <param name="periodicityMask"></param>
        /// <returns>bool array</returns>
        public bool[] GetBoolMask(int periodicity, int periodicityMask)
        {
            var boolMask = new bool[periodicity];
            for (int i = 0; i < periodicity; i++)
            {
                int testParam = (1 << i);
                boolMask[i] = (periodicityMask & testParam) != 0;
            }
            return boolMask;
        }

        /// <summary>
        /// Get int number from bool array
        /// </summary>
        /// <param name="boolMask"></param>
        /// <returns>Int result number</returns>
        public int GetIntMask(bool[] boolMask)
        {
            int result = 0;
            for (int i = 0; i < boolMask.Count(); i++)
            {
               result = (boolMask[i]) ? result | 1 << i : result;
            }
            return result;
        }
    }
}
